package com.esm.pdawms.activity;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Vibrator;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.esm.pdawms.R;
import com.esm.pdawms.adapter.ChurukudanAdapter;
import com.esm.pdawms.database.manager.SystemCenter;
import com.esm.pdawms.model.Churukuhp;
import com.esm.pdawms.model.Linliaohp;
import com.esm.pdawms.util.HttpRequest;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import zuo.biao.library.base.BaseActivity;
import zuo.biao.library.interfaces.OnHttpResponseListener;
import zuo.biao.library.model.Entry;
import zuo.biao.library.ui.EditTextInfoActivity;
import zuo.biao.library.util.JSON;

public class ChukudanActivity extends BaseActivity implements View.OnClickListener, MyReceiver.Message {
    private static final String TAG = "ChukudanActivity";

    public static Intent createIntent(Context context) {
        return new Intent(context, ChukudanActivity.class);
    }

    MyReceiver myReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chukudan);

        initView();
        initData();
        initEvent();

        myReceiver = new MyReceiver();
        myReceiver.message = this;
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.ACTION_DECODE_DATA");
        intentFilter.addAction("com.scanner.broadcast");
        registerReceiver(myReceiver, intentFilter);

        scanChukudan(SystemCenter.getInstance().esmcode);
    }

    public static final int BAOJING = 1819;//报警
    public static final int CHUKUDO = 1820;//出库

    public Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (BAOJING == msg.what) {
                baojing();
            } else if (CHUKUDO == msg.what) {
                chukuone();
            }
        }
    };

    private void chukuone() {
        if (SystemCenter.getInstance().lldan == null) {
            return;
        }

        boolean isfind = false;
        for (int i=0; i < SystemCenter.getInstance().churukuhpList.size(); i++) {
            Churukuhp lldan = SystemCenter.getInstance().churukuhpList.get(i);
            if (lldan.getHpcode().compareToIgnoreCase(SystemCenter.getInstance().lldan.getHpcode()) != 0)
                continue;
            if (_type.compareToIgnoreCase("3") == 0 || _type.compareToIgnoreCase("10") == 0
                    || _type.compareToIgnoreCase("11") == 0 || _type.compareToIgnoreCase("16") == 0) {
                //如果有出库单批号，则需要按批号出
                String strph = SystemCenter.getInstance().lldan.getPh();
                if (lldan.getPh().length() > 1 && lldan.getPh().compareToIgnoreCase(strph) != 0) {
                    continue;
                }
                isfind = true;
                SystemCenter.getInstance().lldan.setNum(lldan.getNum());
                break;
            } else {
                if (lldan.getNum() == lldan.getFnum()) {
                    showShortToast("此货品已出库！");
                    return;
                }
                isfind = true;
                SystemCenter.getInstance().lldan.setNum(lldan.getNum());
                break;
            }
        }

        if (isfind) {
            SystemCenter.getInstance().chukudanname = tv_title.getText().toString();
            SystemCenter.getInstance().chukudanbh = _danbh;
            Intent intent = new Intent(this, ChukuActivity.class);
            startActivityForResult(intent, 60001);
        } else {
            showShortToast("此物料非出库单货品！");
        }

    }

    AssetFileDescriptor afd = null;
    AssetManager am = null;
    //错误扫码报警
    void baojing() {
        Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
        //这里示例的代码是使用点击按钮的时候可以实现震动，在按钮的点击事件的函数中添加这样几句话
        /*这里使用的是一个长整型数组，数组的a[0]表示静止的时间，a[1]代表的是震动的时间，然后数组的a[2]表示静止的时间，
         * a[3]代表的是震动的时间……依次类推下去，然后这里的代码有一点小小的改变
         */
        long[] patter = {50, 1000};
        vibrator.vibrate(patter, -1);

        //播放声音
        if (am == null) {
            am = getAssets();
            try {
                afd = am.openFd("14184.mp3");
            } catch (IOException e) {

            }
        }
        initMediaPlayer();
    }

    private final MediaPlayer mediaPlayer = new MediaPlayer();
    private void initMediaPlayer() {
        try {
            mediaPlayer.reset();
            mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
            mediaPlayer.prepare();
            mediaPlayer.start();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private ListView lv_hpcode;
    private TextView tv_dqzkinfo;
    private EditText edit_lldcode;
    private EditText edit_type;
    private TextView tv_title;
    private TextView tv_hegezs;
    private TextView tv_ywcs;
    private TextView tv_qrrk;

    @Override
    public void initView() {
        lv_hpcode = (ListView) findViewById(R.id.lv_hpcode);
        tv_dqzkinfo = (TextView) findViewById(R.id.tv_dqzkinfo);
        edit_lldcode = (EditText) findViewById(R.id.edit_lldcode);
        edit_type = (EditText) findViewById(R.id.edit_type);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_hegezs  = (TextView) findViewById(R.id.tv_hegezs);
        tv_ywcs  = (TextView) findViewById(R.id.tv_ywcs);
        tv_qrrk  = (TextView) findViewById(R.id.tv_qrrk);
        //禁止响应按键焦点
        lv_hpcode.setFocusable(false);
        reset();
    }

    private void reset() {
        tv_dqzkinfo.setText("");
        edit_lldcode.setText("");
        edit_type.setText("");
        _danbh = "";
        SystemCenter.getInstance().churukuhpList.clear();
        updateData();
    }

    private ChurukudanAdapter adapter;

    private void setList(List<Entry<Integer, String>> list) {
        if (list == null) {
            return;
        }
        if (adapter == null) {
            adapter = new ChurukudanAdapter(context);
            lv_hpcode.setAdapter(adapter);
        }
        adapter.refresh(list);
    }

    private List<Entry<Integer, String>> demodataList;

    protected List<Entry<Integer, String>> getList() {
        demodataList = new ArrayList<Entry<Integer, String>>();
        for (int i = 0; i < SystemCenter.getInstance().churukuhpList.size(); i++) {
            demodataList.add(new Entry<Integer, String>(i, ""));
        }
        return demodataList;
    }

    void updateData() {
        setList(getList());

        if (_type.compareToIgnoreCase("2") == 0 || _type.compareToIgnoreCase("3") == 0 || _type.compareToIgnoreCase("5") == 0
                || _type.compareToIgnoreCase("7") == 0 || _type.compareToIgnoreCase("8") == 0 || _type.compareToIgnoreCase("9") == 0
                || _type.compareToIgnoreCase("10") == 0 || _type.compareToIgnoreCase("13") == 0
                || _type.compareToIgnoreCase("15") == 0 || _type.compareToIgnoreCase("17") == 0) {
            //出库判断 按钮【出库完成转ERP单据】 是否可用
            int size = SystemCenter.getInstance().churukuhpList.size();
            boolean isok = true;
            for (int i = 0; i < size; i++) {
                Churukuhp rukuhp = SystemCenter.getInstance().churukuhpList.get(i);
                if (rukuhp.getFnum() != rukuhp.getNum()) {
                    isok = false;
                    break;
                }
            }
            if (isok) {
                tv_qrrk.setEnabled(true);
                tv_dqzkinfo.setText("此出库单的货品已完成出库！");
            } else {
                tv_qrrk.setEnabled(false);
            }
        }

    }

    @Override
    public void initData() {

    }

    @Override
    public void initEvent() {
        findViewById(R.id.tv_qrrk).setOnClickListener(this);
        adapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
                //点击货品检验
                onPopjy(pos);
            }
        });
    }

    int selectpos = 0;
    private void onPopjy(int pos) {
        //检验货品是否合格
        //类型:0=半成品入库,1=成品缴库单,2=半成品出库,3=成品销货单,4=生产退料单,5=生产补料单,6=非生产退料单,7=非生产补料单,
        // 8=生产领料单,9=非生产领料单,10=借出单,11=借还入单,12=库存调拨入库单,13=库存调拨出库单,14=库存调整入库单,
        // 15=库存调整出库单,16=销货退回入库单,17=进货退回出库单,18=采购入库单
        if (_type.compareToIgnoreCase("2") == 0 || _type.compareToIgnoreCase("3") == 0 || _type.compareToIgnoreCase("5") == 0
                || _type.compareToIgnoreCase("7") == 0 || _type.compareToIgnoreCase("8") == 0 || _type.compareToIgnoreCase("9") == 0
                || _type.compareToIgnoreCase("10") == 0 || _type.compareToIgnoreCase("13") == 0
                || _type.compareToIgnoreCase("15") == 0 || _type.compareToIgnoreCase("17") == 0) {
            return;
        }
        int size = SystemCenter.getInstance().churukuhpList.size();
        if (pos >= size) {
            return;
        }
        selectpos = pos;
        SystemCenter.getInstance().rukuhp = SystemCenter.getInstance().churukuhpList.get(pos);
        //可以修改，如果单子已有小标入库，则在JyhpnumActivity会提示不能修改
        if (SystemCenter.getInstance().rukuhp.getHegenum() > 0) {
            showShortToast("已检验完成！");
            return;
        }

        Intent intent = JyhpnumActivity.createIntent(this);
        startActivityForResult(intent, 123);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_qrrk:
                onQrrk();
                break;
        }
    }

    //类型:0=半成品入库,1=成品缴库单,2=半成品出库,3=成品销货单,4=生产退料单,5=生产补料单,6=非生产退料单,7=非生产补料单,
    // 8=生产领料单,9=非生产领料单,10=借出单,11=借还入单,12=库存调拨入库单,13=库存调拨出库单,14=库存调整入库单,
    // 15=库存调整出库单,16=销货退回入库单,17=进货退回出库单,18=采购入库单
    String _type = "";
    //出入库详情
    void scanChukudan(String danbh) {
        showProgressDialog(R.string.loading);
        try {
            HttpRequest.bcpcpdandetail(danbh, 0, new OnHttpResponseListener() {
                @Override
                public void onHttpResponse(int requestCode, String resultJson, Exception e) {
                    dismissProgressDialog();

                    JSONObject jsonObject = JSON.parseObject(resultJson);
                    int code = 0;
                    if (jsonObject != null) {
                        code = jsonObject.getInteger("code");
                    } else {
                        showShortToast(getString(R.string.wlwlj));
                        tv_dqzkinfo.setText(getString(R.string.wlwlj));
                        return;
                    }
                    if (code == 1) {
                        String data = jsonObject.getString("data");
                        JSONObject jsonObject2 = JSON.parseObject(data);
                        String strtype = jsonObject2.getString("strtype");
                        edit_type.setText(strtype);
                        String type = jsonObject2.getString("type");
                        //类型:0=半成品入库,1=成品缴库单,2=半成品出库,3=成品销货单,4=生产退料单,5=生产补料单,6=非生产退料单,7=非生产补料单,
                        // 8=生产领料单,9=非生产领料单,10=借出单,11=借还入单,12=库存调拨入库单,13=库存调拨出库单,14=库存调整入库单,
                        // 15=库存调整出库单,16=销货退回入库单,17=进货退回出库单,18=采购入库单
                        if (type.compareToIgnoreCase("0") == 0) {
                            tv_title.setText("半成品入库申请单");
                            tv_ywcs.setText("已入库");
                            tv_dqzkinfo.setText("正确的半成品入库申请单,\n请点击列表的货品完成检验！");
                            tv_hegezs.setText("合格数");
                        } else if (type.compareToIgnoreCase("1") == 0) {
                            tv_title.setText("成品入库申请单");
                             tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的成品入库申请单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("2") == 0) {
                            tv_title.setText("半成品出库申请单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的半成品出库申请单，\n出库请扫货品小标！");
                        } else if (type.compareToIgnoreCase("3") == 0) {
                            tv_title.setText("成品出库申请单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的成品出库申请单，\n出库请扫货品小标！");
                        } else if (type.compareToIgnoreCase("4") == 0) {
                            tv_title.setText("退料申请单");//,4=退料单,5=补料单
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的退料申请单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("5") == 0) {
                            tv_title.setText("补料申请单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的补料申请单，\n领料请扫货品小标！");
                        } else if (type.compareToIgnoreCase("6") == 0) {
                            tv_title.setText("非生产退料申请单");
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的非生产退料申请单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("7") == 0) {
                            tv_title.setText("非生产补料申请单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的非生产补料申请单，\n领料请扫货品小标！");
                        } else if (type.compareToIgnoreCase("8") == 0) {
                            tv_title.setText("生产领料申请单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的生产领料申请单，\n领料请扫货品小标！");
                        } else if (type.compareToIgnoreCase("9") == 0) {
                            tv_title.setText("非生产领料申请单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的非生产领料申请单，\n领料请扫货品小标！");
                        } else if (type.compareToIgnoreCase("10") == 0) {
                            tv_title.setText("借出单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的借出单，\n出库请扫货品小标！");
                        } else if (type.compareToIgnoreCase("11") == 0) {
                            tv_title.setText("借还入单");
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的借还入单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("12") == 0) {
                            tv_title.setText("库存调拨入库单");
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的库存调拨入库单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("13") == 0) {
                            tv_title.setText("库存调拨出库单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的库存调拨出库单，\n出库请扫货品小标！");
                        } else if (type.compareToIgnoreCase("14") == 0) {
                            tv_title.setText("库存调整入库单");
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的库存调整入库单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("15") == 0) {
                            tv_title.setText("库存调整出库单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的库存调整出库单，\n出库请扫货品小标！");
                        } else if (type.compareToIgnoreCase("16") == 0) {
                            tv_title.setText("销货退回入库单");
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的销货退回入库单,\n请点击列表的货品完成检验！");
                        } else if (type.compareToIgnoreCase("17") == 0) {
                            tv_title.setText("进货退回出库单");
                            tv_hegezs.setText("总数");
                            tv_ywcs.setText("已出库");
                            tv_dqzkinfo.setText("正确的库存调整出库单，\n出库请扫货品小标！");
                        }  else if (type.compareToIgnoreCase("18") == 0) {
                            tv_title.setText("采购入库单");
                            tv_ywcs.setText("已入库");
                            tv_hegezs.setText("合格数");
                            tv_dqzkinfo.setText("正确的采购送检单编号,\\n请点击列表的大箱完成检验！");
                        }

                        //类型:0=半成品入库,1=成品缴库单,2=半成品出库,3=成品销货单,4=生产退料单,5=生产补料单,6=非生产退料单,7=非生产补料单,
                        // 8=生产领料单,9=非生产领料单,10=借出单,11=借还入单,12=库存调拨入库单,13=库存调拨出库单,14=库存调整入库单,
                        // 15=库存调整出库单,16=销货退回入库单,17=进货退回出库单,18=采购入库单
                        _type = type;

                        if (_type.compareToIgnoreCase("2") == 0 || _type.compareToIgnoreCase("3") == 0 || _type.compareToIgnoreCase("5") == 0
                                || _type.compareToIgnoreCase("7") == 0 || _type.compareToIgnoreCase("8") == 0 || _type.compareToIgnoreCase("9") == 0
                                || _type.compareToIgnoreCase("10") == 0 || _type.compareToIgnoreCase("13") == 0
                                || _type.compareToIgnoreCase("15") == 0 || _type.compareToIgnoreCase("17") == 0) {
                            //出库单显示按钮【出库完成转ERP单据】
                            tv_qrrk.setVisibility(View.VISIBLE);
                            tv_qrrk.setEnabled(false);
                        } else {
                            tv_qrrk.setVisibility(View.GONE);
                        }
                        JSONArray jsonArray = jsonObject2.getJSONArray("bomlist");
                        SystemCenter.getInstance().churukuhpList.clear();
                        for (int i = 0; i < jsonArray.size(); i++) {
                            JSONObject a = jsonArray.getJSONObject(i);

                            Churukuhp hp = new Churukuhp();
                            hp.setHpname(a.getString("hpname"));
                            hp.setHpcode(a.getString("hpcode"));
                            String strNum = a.getString("num");
                            try {
                                if (type.compareToIgnoreCase("18") == 0) {
                                    hp.setNummax(Float.parseFloat(strNum));//采购需求总数
                                    hp.setNum(a.getFloat("ynum"));//待检数
                                    hp.setHegenum(a.getFloat("ydbqnum"));//合格数
                                    hp.setFnum(a.getFloat("yrknum"));//已入库数
                                    hp.setDxname(a.getString("hpbh"));
                                } else {
                                    hp.setNum(Float.parseFloat(strNum)); //待检数
                                    hp.setFnum(a.getFloat("fnum"));
                                    hp.setHegenum(a.getInteger("hegenum"));
                                }
                                hp.setKwbh(a.getString("kwbh"));
                                hp.setLastph(a.getString("lastph"));//该货品最后一次入库的批号
                                hp.setPh(a.getString("ph"));
                                hp.setTjkw(a.getString("tjkw"));
                                hp.setType(type);

                            } catch (Exception e1) {

                            }
                            SystemCenter.getInstance().churukuhpList.add(hp);
                        }
                        updateData();
                        if (danbh.compareToIgnoreCase(_danbh) == 0) {

                        } else {
                            _danbh = danbh;
                            edit_lldcode.setText(_danbh);
                        }
                    } else {
                        mHandler.sendEmptyMessage(BAOJING);
                        String msg = jsonObject.getString("msg");
                        showShortToast(msg);
                        tv_dqzkinfo.setText(msg);
                    }

                }
            });
        } catch (Exception e1) {
            showShortToast(getString(R.string.wlwlj));
            tv_dqzkinfo.setText(getString(R.string.wlwlj));
            dismissProgressDialog();
        }
    }

    String _danbh = "";//正确的出入库单号

    @Override
    public void getMsg(String str) {
        if (!isActive) {
            return;
        }
        //通过实现MyReceiver.Message接口可以在这里对MyReceiver中的数据进行处理
        showShortToast(str);
        //禁止响应按键焦点
        lv_hpcode.setFocusable(false);

        //仅出库单可入扫码出库
        if (_type.compareToIgnoreCase("2") == 0 || _type.compareToIgnoreCase("3") == 0 || _type.compareToIgnoreCase("5") == 0
                || _type.compareToIgnoreCase("7") == 0 || _type.compareToIgnoreCase("8") == 0 || _type.compareToIgnoreCase("9") == 0
                || _type.compareToIgnoreCase("10") == 0 || _type.compareToIgnoreCase("13") == 0
                || _type.compareToIgnoreCase("15") == 0 || _type.compareToIgnoreCase("17") == 0) {
            scanHpcode(str);
        }
    }

    //扫小标，准备出库
    void scanHpcode(String hkcode) {
        showProgressDialog(R.string.loading);
        try {
            HttpRequest.hprkcodedetail(hkcode, 0, new OnHttpResponseListener() {
                @Override
                public void onHttpResponse(int requestCode, String resultJson, Exception e) {
                    dismissProgressDialog();

                    JSONObject jsonObject = JSON.parseObject(resultJson);
                    int code = 0;
                    if (jsonObject != null) {
                        code = jsonObject.getInteger("code");
                    } else {
                        showShortToast(getString(R.string.wlwlj));
                        tv_dqzkinfo.setText(getString(R.string.wlwlj));
                        return;
                    }

                    if (code == 1) {
                        String data = jsonObject.getString("data");
                        JSONObject jsonObject2 = JSON.parseObject(data);
                        String hpcode = jsonObject2.getString("hpcode");
                        String state = jsonObject2.getString("state");
                        String cwbh = jsonObject2.getString("cwbh");
                        String ph = jsonObject2.getString("ph");
                        if (state.compareToIgnoreCase("0") == 0) {
                            showShortToast("这是待入库小标");
                        } else if (state.compareToIgnoreCase("1") == 0) {
                            SystemCenter.getInstance().lldan = new Linliaohp(cwbh, hkcode, hpcode, ph);
                            mHandler.sendEmptyMessage(CHUKUDO);
                        } else {
                            showShortToast("这是已出库小标");
                        }
                    } else {
                        mHandler.sendEmptyMessage(BAOJING);
                        String msg = jsonObject.getString("msg");
                        tv_dqzkinfo.setText(msg);
                        showShortToast(msg);
                        reset();
                    }

                }
            });
        } catch (Exception e1) {
            showShortToast(getString(R.string.wlwlj));
            tv_dqzkinfo.setText(getString(R.string.wlwlj));
            dismissProgressDialog();
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 60001:
            case 123:
                scanChukudan(_danbh);
                break;
        }
    }

    boolean isActive = false;
    @Override
    protected void onPause() {
        super.onPause();
        isActive = false;
    }

    @Override
    protected void onResume() {
        super.onResume();
        isActive = true;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(myReceiver);
    }

    private void onQrrk() {
        showProgressDialog(R.string.loading);
        try {

            HttpRequest.sqdanchuku(_danbh, 0, new OnHttpResponseListener() {
                @Override
                public void onHttpResponse(int requestCode, String resultJson, Exception e) {
                    dismissProgressDialog();

                    JSONObject jsonObject = JSON.parseObject(resultJson);
                    int code = 0;
                    if (jsonObject != null) {
                        code = jsonObject.getInteger("code");
                    } else {
                        showShortToast(getString(R.string.wlwlj));
                        tv_dqzkinfo.setText(getString(R.string.wlwlj));
                        return;
                    }

                    if (code == 1) {
                        finish();
                    } else {
                        mHandler.sendEmptyMessage(BAOJING);
                        String msg = jsonObject.getString("msg");
                        tv_dqzkinfo.setText(msg);
                        showShortToast(msg);
                    }
                }
            });

        } catch (Exception e1) {
            showShortToast(getString(R.string.wlwlj));
            tv_dqzkinfo.setText(getString(R.string.wlwlj));
            dismissProgressDialog();
        }
    }
}